package com.example.adapter.media.impl;

import com.example.adapter.media.AdvancedMediaPlayer;
import com.example.adapter.media.MediaPlayer;
import org.springframework.util.StringUtils;

/**
 * @Description TODO
 * @Date 2021/10/29 10:13
 * @Author ZhangJi
 * @Version 1.0
 */
public class MediaAdapter implements MediaPlayer {

  AdvancedMediaPlayer advancedMediaPlayer;

  public MediaAdapter(String audioType) {
    if (!StringUtils.hasLength(audioType)) {
      advancedMediaPlayer = new VlcPlayer();
    }
    switch (audioType){
      case "vlc":
        advancedMediaPlayer = new VlcPlayer();
        break;
      case "mp4":
        advancedMediaPlayer = new Mp4Player();
        break;
      default:
        advancedMediaPlayer = new VlcPlayer();
        break;
    }
  }

  @Override
  public void play(String audioType, String fileName) {
    if (!StringUtils.hasLength(audioType) || !StringUtils.hasLength(fileName)) {
      System.out.println("文件类型或文件名为空，请检查！");
    }
    if ("mp4".equalsIgnoreCase(audioType)) {
      advancedMediaPlayer.playMp4(fileName);
    }else if ("vlc".equalsIgnoreCase(audioType)) {
      advancedMediaPlayer.playVlc(fileName);
    }
  }

}
